package com.amap.api.col.s;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import com.amap.api.col.s.dz;

/* compiled from: NetManger.java */
/* loaded from: classes.dex */
public final class dy extends dt {
    private static dy f;
    private Handler g;

    public static dy b() {
        return c();
    }

    private static synchronized dy c() {
        dy dyVar;
        synchronized (dy.class) {
            try {
                if (f == null) {
                    f = new dy();
                }
                dyVar = f;
            }
        }
        return dyVar;
    }

    private dy() {
        try {
            if (Looper.myLooper() == null) {
                this.g = new a(Looper.getMainLooper(), (byte) 0);
            } else {
                this.g = new a();
            }
        } catch (Throwable th) {
            df.c(th, "NetManger", "NetManger1");
            th.printStackTrace();
        }
    }

    @Deprecated
    private static ea d(dz dzVar, boolean z) throws bv {
        d(dzVar);
        dzVar.a(z ? dz.c.HTTPS : dz.c.HTTP);
        ea eaVar = null;
        long j = 0;
        boolean z2 = false;
        if (b(dzVar)) {
            boolean c = c(dzVar);
            try {
                j = SystemClock.elapsedRealtime();
                eaVar = a(dzVar, a(dzVar, c), c(dzVar, c));
            } catch (bv e) {
                if (e.f() == 21 && dzVar.o() == dz.a.INTERRUPT_IO) {
                    throw e;
                }
                if (!c) {
                    throw e;
                }
                z2 = true;
            }
        }
        if (eaVar == null || eaVar.a == null || eaVar.a.length <= 0) {
            try {
                return a(dzVar, b(dzVar, z2), a(dzVar, j));
            } catch (bv e2) {
                throw e2;
            }
        }
        return eaVar;
    }

    public static ea e(dz dzVar) throws bv {
        return d(dzVar, dzVar.r());
    }

    private static ea a(dz dzVar, dz.b bVar, int i) throws bv {
        try {
            d(dzVar);
            dzVar.a(bVar);
            dzVar.c(i);
            return new dw().a(dzVar);
        } catch (bv e) {
            throw e;
        } catch (Throwable th) {
            th.printStackTrace();
            throw new bv("未知的错误");
        }
    }

    /* compiled from: NetManger.java */
    /* loaded from: classes.dex */
    static class a extends Handler {
        /* synthetic */ a(Looper looper, byte b) {
            this(looper);
        }

        private a(Looper looper) {
            super(looper);
        }

        public a() {
        }

        @Override // android.os.Handler
        public final void handleMessage(Message message) {
            try {
                int i = message.what;
                if (i == 0) {
                    Object obj = message.obj;
                } else if (i != 1) {
                } else {
                    Object obj2 = message.obj;
                }
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }
}
